/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dsw2.veterinarySystem.bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dsw2.veterinarySystem.dao.MascotaDaoLocal;
import mx.its.dsw2.veterinarySystem.enumeraciones.TransactionStatus;
import mx.its.dsw2.veterinarySystem.modelo.Mascota;

/**
 *
 * @author 100101
 */
@Stateless
public class MascotaBl implements MascotaBlLocal {
    @EJB
    private MascotaDaoLocal mascotaDao;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public TransactionStatus register(Mascota mascot) {
        if(mascotaDao.findDuplicity(mascot)){
            return TransactionStatus.TRUNCATED;
        }else{
        mascotaDao.create(mascot);
        return TransactionStatus.REALIZED;
        }
    }

    @Override
    public TransactionStatus modify(Mascota mascot) {
        if(mascot.getId()==null||mascotaDao.find(mascot.getId())==null){
            return TransactionStatus.TRUNCATED;
        }
        mascotaDao.edit(mascot);
        return TransactionStatus.REALIZED;
    }

    @Override
    public TransactionStatus remove(Mascota mascot) {
        if(mascot.getId()==null||mascotaDao.find(mascot.getId())==null){
            return TransactionStatus.TRUNCATED;
        }
        mascotaDao.remove(mascot);
        return TransactionStatus.REALIZED;
    }

    @Override
    public List<Mascota> getAll() {
        return mascotaDao.findAll();
    }

    @Override
    public Mascota getMascotaById(int idMascota) {
        return mascotaDao.find(idMascota);
    }
    
    
    
    
    
    

    
    
}
